classdef meshDM < handle
    %MESH mesh class for DM's EM codes
    
    properties
        hx      %h* -> vector of cell widths in the * direction
        hy
        hz
        x0 = 0
        y0 = 0
        z0 = 0
    end
    
    properties (Dependent = true, SetAccess = private)
       ncx       %nc* -> number of cells in each direction
       ncy
       ncz
       
       nex       %ne* -> number of * edges
       ney
       nez
       
       nc        %nc -> number of cells in the mesh
       nn        %nn -> total number of nodes
       ne        %ne -> total number of edges
       nf        %nf -> total number of faces
       
       xc        %*c -> *-location of cell centres
       yc
       zc        
       
       xn        %*n -> *-location of nodes
       yn
       zn
    end
    
    properties (SetAccess = private)
        %Operators
        CURL    % Curl operator ()
        GRAD    % Gradfient operator ()
        DIV     % Divergence operator ()
        Ae      % Arithmatic averageing to cell edges (ne*nc)
        Af      % Arithmatic averageing to cell faces (nf*nc)
        An      % Arithmatic averageing to cell nodes (nn*nc)
        
        %Edge Grids
        Xe      %Grid of edges pointing in the x direction
        Ye      %Grid of the edges pointing in the y direction
        Ze      %Grid of the edges pointing in the z direction
        
        %Face Grids
        Xf
        Yf
        Zf
        
        %Cell Centre Grid
        CC
    end
    
    methods
        function self = meshDM(hx,hy,hz)
            %msh = meshDM(hx,hy,hz)
            %Class constructor of meshDM
            %Inputs: hx -> vector of cell widths in the x direction
            %        hy -> vector of cell widths in the y direction
            %        hz -> vector of cell widths in the z direction
            
            self.hx = hx(:);
            self.hy = hy(:);
            self.hz = hz(:);
            
            self.getCellCentreGrid;
            self.getEdgeGrid;
            self.getFaceGrid;
            self.getDifferentialOperators;

        end
        
        getEdgeGrid(self)
        getFaceGrid(self)
        getCellCentreGrid(self)
        getDifferentialOperators(self)

        % Getters
        function ncx = get.ncx(self)
            ncx = length(self.hx);
        end
        function ncy = get.ncy(self)
            ncy = length(self.hy);
        end
        function ncz = get.ncz(self)
            ncz = length(self.hz);
        end
        function nex = get.nex(self)
            nex = size(self.Xe,1);
        end
        function ney = get.ney(self)
            ney = size(self.Ye,1);
        end
        function nez = get.nez(self)
            nez = size(self.Ze,1);
        end        
        function nc = get.nc(self)
            nc = length(self.hx)*length(self.hy)*length(self.hz);
        end
        function nn = get.nn(self)
            nn = (self.ncx+1)*(self.ncy+1)*(self.ncz+1);
        end
        function ne = get.ne(self)
            ne = self.ncx*(self.ncy+1)*(self.ncz+1) + ...
                (self.ncx+1)*self.ncy*(self.ncz+1) + ...
                (self.ncx+1)*(self.ncy+1)*(self.ncz);
        end
        function nf = get.nf(self)
            nf = (self.ncx+1)*self.ncy*self.ncz + ...
                self.ncx*(self.ncy+1)*self.ncz + ...
                self.ncx*self.ncy*(self.ncz+1);
        end
        function xn = get.xn(self)
            xn = [0; cumsum(self.hx)] + self.x0;
        end
        function yn = get.yn(self)
            yn = [0; cumsum(self.hy)] + self.y0;
        end
        function zn = get.zn(self)
            zn = [0; cumsum(self.hz)] + self.z0;
        end
        function xc = get.xc(self)
            xc = self.xn(1:end-1) + self.hx/2;
        end
        function yc = get.yc(self)
            yc = self.yn(1:end-1) + self.hy/2;
        end
        function zc = get.zc(self)
            zc = self.zn(1:end-1) + self.hz/2;
        end  
    end
    
end

